//
//  ZLWrongParsingSheetViewController.m
//  ZLExamination
//
//  Created by Zheng on 2017/9/13.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLWrongParsingSheetViewController.h"
#import "ZLWrongParsingSheetCell.h"

#import "ZLExamResultModel.h"

@interface ZLWrongParsingSheetViewController ()

@end

@implementation ZLWrongParsingSheetViewController

#pragma mark - 点击事件
- (void)scroolToDesignationRowWith:(NSInteger)rowNumber {
    if (_clickCallBack) {
        _clickCallBack(rowNumber);
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
}


#pragma mark - 传值
- (void)setQuestions:(NSArray<NSArray *> *)questions {
    _questions = questions;
}

#pragma mark - 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showBackButtonWithTitle:@"╳" withFont:[UIFont boldSystemFontOfSize:20]];
    
    self.navigationItem.title = @"答题卡";
    
    [self.myTableView registerClass:[ZLWrongParsingSheetCell class] forCellReuseIdentifier:kZLWrongParsingSheetCell_ID];
    self.myTableView.backgroundColor = [UIColor whiteColor];
    
}



#pragma mark - tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    __weak typeof(self) weakSelf = self;
    
    ZLWrongParsingSheetCell *cell = [tableView dequeueReusableCellWithIdentifier:kZLWrongParsingSheetCell_ID forIndexPath:indexPath];
    
    if (indexPath.section == 0) {
        [cell setNumbersWithRows:[_questions[0] count] withSingles:_questions[indexPath.section]];
        
    } else {
        [cell setNumbersWithRows:[_questions[1] count] withMultiple:_questions[indexPath.section] withSingleRows:[_questions[0] count]];
    }
    
    cell.clickCallBack = ^(NSInteger number) {
        [weakSelf scroolToDesignationRowWith:number];
    };
    
    return cell;
}


#pragma mark - tableview delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSInteger rows = 0;
    
    if (indexPath.section == 0) {
        CGFloat a = [_questions[0] count]/5.;
        NSInteger b = [_questions[0] count]/5;
        rows = a>b? b+1: b;
    } else {
        CGFloat a = [_questions[1] count]/5.;
        NSInteger b = [_questions[1] count]/5;
        rows = a>b? b+1: b;
    }
    
    return rows*(kSCREEN_WIDTH/5);
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return @"单选题";
    } else {
        return @"多选题";
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}


#pragma mark - 返回
- (void)backBarButtonPressed:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{}];
}


@end
